package com.singzi.leetcode.N800;

import java.util.TreeMap;

public class T0791 {
}
class Solution0791 {
    public int smallestDistancePair(int[] nums, int k) {
        TreeMap<Integer, Integer> map = new TreeMap<>();
        int dis;
        for(int i = 0;i < nums.length-1;i++){
            for(int j = i+1; j < nums.length;j++){
                dis = Math.abs(nums[i] - nums[j]);
                map.put(dis, map.getOrDefault(dis, 0)+1);
            }
        }
        int target = 0;

        for(int key:map.keySet()){
            k = k - map.get(key);
            if(k <= 0 ){

                target = key;
                break;
            }

        }
        return target;

    }
}
